import { getModuleTypeList } from '@/api/module/module';
import { BasicColumn, FormSchema } from '@/components/Table';

export const columns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'name',
    width: 120,
  },
  {
    title: '类型',
    dataIndex: 'type',
    width: 100,
  },
  {
    title: '键名',
    dataIndex: 'key',
    width: 120,
  },
  {
    title: '值',
    dataIndex: 'value',
    width: 200,
  },
  {
    title: '描述',
    dataIndex: 'desc',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'type',
    label: '类型',
    component: 'Select',
    componentProps: {
      options: [
        { label: 'html(富文本)', value: 'html' },
        { label: 'url(链接)', value: 'url' },
        { label: 'text(文本)', value: 'text' },
        { label: 'image(图片)', value: 'image' },
      ],
    },
    colProps: { span: 8 },
  },
  {
    field: 'key',
    label: '键名',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'type',
    label: '类型',
    component: 'ApiSelect',
    required: true,
    colProps: { span: 24 },
    componentProps: {
      api: getModuleTypeList,
      resultField: 'list',
      labelField: 'type',
      valueField: 'type',
      immediate: true,
    },
  },
  {
    field: 'key',
    label: '键',
    component: 'Input',
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'value',
    label: '值',
    component: 'Input',
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'desc',
    label: '描述',
    component: 'InputTextArea',
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'extra',
    label: '额外配置',
    component: 'InputTextArea',
    colProps: { span: 24 },
    componentProps: {
      placeholder: '请输入JSON格式的配置，例如：{"a.href":true,"a.target":"_blank"}',
    },
  },
];
